#from generic.album import Album
from tidal.constants import IMG_URL
from cache.cache import cache
from cache.constants import TIDAL_ARTIST
import tidal.track
import tidal.artist

class TidalAlbum:
  def __init__(self, id, title):
    self.id = id
    self.title = title

  def set_raw_data(self, album_data):
    self.id = album_data["id"]
    self.title = album_data["title"]
    self.duration = album_data["duration"]
    self.track_amount = album_data["numberOfTracks"]
    self.release_date = album_data["releaseDate"]
    def get_artist(artist_data):
      cache_key = TIDAL_ARTIST % artist_info["id"]
      if cache.has(cache_key):
        artist = cache.get(cache_key)
      else:
        artist = tidal.artist.TidalArtist(artist_data["id"], artist_data["name"])
        cache.set(cache_key, artist)
      return artist
    self.artists = list(map(get_artist, album_data["artists"]))

  @property
  def picture_url(self, width = 512, height = 512):
      return IMG_URL.format(width = width,
                            height = height,
                            id = self.id,
                            id_type = 'albumid')
